package cn.ywang.pattern.singleton.threadlocal;

/**
 * 单线程单例，伪单例，在同一线程内保证单例
 *
 * @author BeatificWang
 * @date 2019/3/10 19:08
 */
public class ThreadLocalSingleton {

	private ThreadLocalSingleton() {
	}

	private static final ThreadLocal<ThreadLocalSingleton> threadLocalSingleton =
			new ThreadLocal<ThreadLocalSingleton>() {
				@Override
				protected ThreadLocalSingleton initialValue() {
					return new ThreadLocalSingleton();
				}
			};

	public static ThreadLocalSingleton getInstance() {
		return threadLocalSingleton.get();
	}
}
